package com.gnxk.datasource.web;

import com.gnxk.datasource.config.DbContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class TestDataSourceController {

    @Autowired
    JdbcTemplate jdbcTemplate;

    @RequestMapping("f/test/datasource")
    public void testDataSource(){
        String str = "select name from sys_user where id = '1'";
        Map<String, Object> map = jdbcTemplate.queryForMap(str);
        System.out.println("默认数据源查询："+map.get("name").toString());
        DbContextHolder.setDataSource("sdeDataSource");
        String sdestr = "select f_xzqmc from current.area_srid where f_xzqdm = '140403'";
        Map<String, Object> sdeMap = jdbcTemplate.queryForMap(sdestr);
        System.out.println("切换后数据源查询："+sdeMap.toString());
    }

}
